package com.api.shopapi.mapper;

import com.api.shopapi.entity.GoodsClassGovernment;
import com.api.shopapi.entity.dto.GoodsClassGovernmentDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface GoodsClassGovernmentMapper {

    @Insert("insert into  goods_class_government (" +
            "GoodsClassGovernmentCode, " +
            "ParentGoodsClassGovernmentCode, " +
            "GoodsClassCode, " +
            "ParentGoodsClassCode, " +
            "GovernmentCode, " +
            "Name, " +
            "Icon, " +
            "Sort, " +
            "Status, " +
            "IsGroup, " +
            "IsRecommend" +
            ") " +
            "VALUES " +
            "(" +
            "#{goodsClassGovernment.GoodsClassGovernmentCode}," +
            "#{goodsClassGovernment.ParentGoodsClassGovernmentCode}," +
            "#{goodsClassGovernment.GoodsClassCode}," +
            "#{goodsClassGovernment.ParentGoodsClassCode}," +
            "#{goodsClassGovernment.GovernmentCode}," +
            "#{goodsClassGovernment.Name}," +
            "#{goodsClassGovernment.Icon} ," +
            "#{goodsClassGovernment.Sort} ," +
            "#{goodsClassGovernment.Status} ," +
            "#{goodsClassGovernment.IsGroup},   " +
            "#{goodsClassGovernment.IsRecommend}   " +
            ") ")
    int insert(@Param("goodsClassGovernment") GoodsClassGovernment goodsClassGovernment);


    @Update("update goods_class_government set ParentGoodsClassGovernmentCode=#{goodsClassGovernment.ParentGoodsClassGovernmentCode},Name=#{goodsClassGovernment.Name},Icon=#{goodsClassGovernment.Icon}," +
            "Sort=#{goodsClassGovernment.Sort},Status=#{goodsClassGovernment.Status},IsGroup=#{goodsClassGovernment.IsGroup} " +
            "where GoodsClassGovernmentCode=#{goodsClassGovernment.GoodsClassGovernmentCode}")
    int update(@Param("goodsClassGovernment") GoodsClassGovernment goodsClassGovernment);

    @Delete("delete from goods_class_government where GoodsClassGovernmentCode=#{goodsClassGovernmentCode}")
    int delete(@Param("goodsClassGovernmentCode") String goodsClassGovernmentCode);

    @Select("select * from goods_class_government where GoodsClassGovernmentCode=#{goodsClassGovernmentCode}  limit 1")
    GoodsClassGovernment getByGoodsClassGovernmentCode(@Param("goodsClassGovernmentCode") String goodsClassGovernmentCode);

    @Select("select * from goods_class_government where Name=#{name}   and GovernmentCode=#{governmentCode} and Status=1 limit 1")
    GoodsClassGovernment getByName(@Param("name") String Name,
                                   @Param("governmentCode") String governmentCode);

    @Select("select * from goods_class_government where GovernmentCode=#{GovernmentCode} and Status=1 order by Sort desc")
    List<GoodsClassGovernment> getListByGovernmentCode(@Param("GovernmentCode") String GovernmentCode);


    @Select("select * from goods_class_government where GovernmentCode=#{GovernmentCode} and ParentGoodsClassCode=#{ParentGoodsClassCode} order by Sort desc")
    List<GoodsClassGovernmentDTO> getAllListByParentGoodsClassCode(@Param("GovernmentCode") String GovernmentCode,@Param("ParentGoodsClassCode") String ParentGoodsClassCode);


    @Select("select * from goods_class_government" +
            " where GovernmentCode=#{GovernmentCode}" +
            " and ParentGoodsClassCode=#{ParentGoodsClassCode}" +
            " and Status=1 order by Sort desc")
    List<GoodsClassGovernmentDTO> getListByParentGoodsClassCode(@Param("GovernmentCode") String GovernmentCode,@Param("ParentGoodsClassCode") String ParentGoodsClassCode);


    @Select("<script>" +
            "select * from goods_class_government " +
            "where GovernmentCode=#{GovernmentCode} "+
            "<if test ='name !=null and name!=\"\" '>" +
            "and Name like concat('%',#{name},'%') " +
            "</if>" +
            "<if test ='status!=-1'>" +
            "and Status=#{status} " +
            "</if>" +
            "order by Sort desc" +
            "</script>")
    List<GoodsClassGovernment> getPageList(@Param("GovernmentCode") String GovernmentCode,@Param("name") String name,@Param("status")int status);

    @Select("<script>" +
            "select * from goods_class_government " +
            "where GovernmentCode=#{GovernmentCode} " +
            "and ParentGoodsClassCode=#{ParentGoodsClassCode} "+
            "<if test ='name !=null and name!=\"\" '>" +
            "and Name like concat('%',#{name},'%') " +
            "</if>" +
            "order by Sort desc" +
            "</script>")
    List<GoodsClassGovernmentDTO> getPageListByParentGoodsClassCode(@Param("GovernmentCode") String GovernmentCode,@Param("name") String name,@Param("ParentGoodsClassCode") String ParentGoodsClassCode);


    @Select("select * from goods_class_government where GovernmentCode=#{GovernmentCode} " +
            "and ParentGoodsClassCode != #{ParentGoodsClassCode} " +
            "order by Sort desc")
    List<GoodsClassGovernment> getSecondClassList(@Param("GovernmentCode") String GovernmentCode,@Param("ParentGoodsClassCode") String ParentGoodsClassCode);



    @Select("select * from goods_class_government where GovernmentCode=#{GovernmentCode} " +
            "and ParentGoodsClassCode = #{ParentGoodsClassCode} " +
            "order by Sort desc")
    List<GoodsClassGovernment> getFirstClassList(@Param("GovernmentCode") String GovernmentCode,@Param("ParentGoodsClassCode") String ParentGoodsClassCode);









}
